package com.lagou.zxy;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * @program: stage-5-module-1
 * @description:
 * @author: zhangxiaoyang
 * @date: 12/30/20 11:09 AM
 **/
public class RedisClusterMain {

    public static void main(String[] args) {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        Set<HostAndPort> jedisClusterNodes = new HashSet<>();
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7001));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7002));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7003));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7004));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7005));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7006));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7007));
        jedisClusterNodes.add(new HostAndPort("8.131.255.51", 7008));

        JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, jedisPoolConfig);
        jedisCluster.set("name:011", "我是中国人");
        String value = jedisCluster.get("name:011");
        System.out.println("redis-cluster的key=\"name:011\"返回值:" + value);
    }
}
